gusucode.com > ASP+ACCESS在线手机销售系统(论文+源代码+答辩PPT) > ASP+ACCESS在线手机销售系统(论文+源代码+答辩PPT)\9)ASP 在线手机销售系统\HandsetPro\handset\include\ShowSpecialProduct.asp
<% ' ================================================= '过程名:ShowSpecialProduct '作 用:显示热门产品 '参 数: 'strFilter: 选择条件,有以下可选项: ' "Hot": 购买次数最高的产品 ' "Recommended": 推荐度 ' "Cheap": 最优惠产品 ' 其他默认为"Hot" 'nCount:最大显示数量 ' ================================================= Sub ShowSpecialProduct(strFilter, nCount) dim strSpecialText if strFilter = "Hot" then strSpecialText = "热门产品" elseif strFilter = "Recommended" then strSpecialText = "推荐产品" elseif strFilter = "Cheap" then strSpecialText = "最优惠产品" else strFilter = "Hot" strSpecialText = "热门产品" end if %> <TABLE cellSpacing = "0" cellPadding = "0" width = "100%" border = "0" ID = "Table1"> <TBODY> <TR> <TD height = "20" background = "images/titlebg.gif" align = center><strong><%=strSpecialText%></strong> </TD> </TR> <TR> <TD height = "5"></TD> </TR> <TR> <TD vAlign = "top"> <table width = "95%" border = "0" align = "center" cellpadding = "0" cellspacing = "0" ID = "Table2"> <tr> <td> <% call ShowSpecialProductList(strFilter, nCount) %> </td> </tr> </table> </TD> </TR> <TR> <TD height = "5"></TD> </TR> </TBODY> </TABLE> <% end sub ' ================================================= '过程名:ShowSpecialProductList '作 用:显示热门产品列表数据(无修饰) '参 数: 'strFilter: 选择条件,有以下可选项: ' "Hot": 购买次数最高的产品 ' "Recommended": 推荐度 ' "Cheap": 最优惠产品 ' 其他默认为"Hot" 'nCount:最大显示数量 ' ================================================= Sub ShowSpecialProductList(strFilter, nCount) dim strSQL, rsObj, productName, i '检查nCount的合法性 nCount = CInt(nCount) if nCount > 20 then nCount = 20 if nCount < 1 then nCount = 1 Response.Write "<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0' ID = 'Table3'>" '根据strFilter参数组织SQL语句, '要在排序条件的最后加入以id排序, '否则可能因为多个记录在前面排序字段处的值相同,使得筛选出的记录数超过nCount if strFilter = "Hot" then strSQL = "SELECT TOP " & nCount & " ID, [Name] FROM product " strSQL = strSQL & " ORDER BY buyNum desc,id desc" elseif strFilter = "Recommended" then strSQL = "SELECT TOP " & nCount & " ID, [Name] FROM product " strSQL = strSQL & " ORDER BY recommend desc, recommenddate desc, id desc" elseif strFilter = "Cheap" then '因为用到了除法,所以要加上对分母不为0的判断 strSQL = "SELECT TOP " & nCount & " ID, [Name], memberPrice/marketPrice AS Discount " strSQL = strSQL & " FROM Product WHERE marketPrice <> 0 " strSQL = strSQL & " ORDER BY memberPrice/marketPrice, id desc" else strSQL = "SELECT TOP " & nCount & " ID, [Name] FROM Product " strSQL = strSQL & " ORDER BY buyNum desc,id desc" end if set rsObj = conn.Execute (strSQL) if rsObj.EOF And rsObj.BOF then Response.Write "目前没有此类数据……" end if i = 1 '输出列表,在这里尤其要注意避免字符串拼接 do while not (rsObj.eof or err) Response.Write "<tr><td height = 23>" Response.Write "<img src = images/cha1.gif>" '如果是显示最优惠产品,则显示此产品的打的程度,否则直接显示产品名字 if strFilter = "Cheap" then productName = i & "." & rsObj("name") & "(<font color = red>" & FormatNumber(rsObj("Discount")*10,1) & "</font>折)" else productName = rsObj("name") '如果名字太长,将其截断 if len(productName) > 14 then productName = left(productName,9)&"..." end if end if Response.Write "<a href = ProductDetail.asp?id=" & rsObj("ID") & "> " & productName & "</a>" Response.Write "</td></tr>" i = i+1 if i>100 then exit do rsObj.MoveNext loop '关闭集合,但不要关闭连接,因为其他地方可能要用 rsObj.Close() Set rsObj = Nothing Response.Write "</table>" end sub ' ================================================= '过程名:ShowTheBest '作 用:显示最新推荐手机 '参 数:无 ' ================================================= Sub ShowTheBest() dim strSQL, rsObj dim strTemp, strSrc, strIntro strSQL = "SELECT top 1 * FROM product " strSQL = strSQL & " WHERE Recommend > 0 " strSQL = strSQL & " ORDER by RecommendDate DESC, buyNum DESC, ID DESC" set rsObj = conn.execute (strSQL) '如果没有找到商品,则退出此过程 if rsObj.EOF and rsObj.BOF then Response.Write "<br><br>出错啦!可能是没有检索到数据或者检索过程出错。<br><br>" rsObj.Close() Set rsObj = Nothing Exit Sub end if '如果找到商品,则输出信息 '确定大图片URL if rsObj("bigImg") = "nothing" then strSrc = "images/noBigImg.gif" else strSrc = "bigImg/"&rsObj("bigImg") end if '只显示部分商品介绍, '注意这里一定要用Convert函数对介绍内容进行HTML编码和加入换行符<br> strIntro = Convert(rsObj("introduce")) if lenB(strIntro)>300 then strIntro = leftB(strIntro,300) end if %> <table width = "100%" border = "0" bordercolordark = #ffffff bordercolorlight = #FFCF00 cellspacing = "0" cellpadding = "0" align = "center" ID = "Table20"> <tr> <TD class = "tabTitle" height = "22" bgColor=<%=conTitleColor%> colspan = 2><b>推荐手机</b></TD> </tr> <tr><td height = 10 colspan = 2></td></tr> <tr> <td width = "160" align = center> <a href = ProductDetail.asp?id=<%=rsObj("id")%>> <img src = "<%=strSrc%>" height=<%=conBigImageHeight%> border = 0></a><br> <a href = "ProductDetail.asp?id=<%=rsObj("id")%>" title = "点击查看具体信息"><b><%=rsObj("Name")%></b></a><br> </td> <td ><b>[手机介绍] </b><br> <%=strIntro%><br> <strike>市场价:<%=rsObj("marketPrice")%> 元 </strike> 商城价:<%=rsObj("memberPrice")%>元<br> 立即节省:<font color = RED><%=rsObj("marketPrice")-rsObj("memberPrice")%></font>元 <a href = "shopCart.asp?productID=<%=rsObj("id")%>"> <img src = "images/cart.gif" width = "22" height = "22" border = "0" align = "absmiddle"> 放入购物车</a> </td> </tr> <tr><td height = 10 colspan = 2></td></tr> </table> <% rsObj.Close() set rsObj = Nothing end sub %>